package com.example.administrator.maizuofilm.movie.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.maizuofilm.BaseFragment;
import com.example.administrator.maizuofilm.R;
import com.example.administrator.maizuofilm.hot.fragment.HotFragment;
import com.example.administrator.maizuofilm.movie.adapter.MovieFragmentPagerAdapter;
import com.example.administrator.maizuofilm.notshow.NotShowFragment;
import com.example.administrator.maizuofilm.recommend.fragment.RecommendFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by Administrator on 2016/7/11.
 */
public class MovieFragment extends BaseFragment {
    @InjectView(R.id.viewpager_body_movie)
    ViewPager viewpagerBodyMovie;
    @InjectView(R.id.tablayout_body_movie)
    TabLayout tablayoutBodyMovie;
    private List<Fragment> fragments;
    private MovieFragmentPagerAdapter pagerAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_movie, null);
        ButterKnife.inject(this, view);
        init();
        addFragment();
        viewpagerBodyMovie.setAdapter(pagerAdapter);
        tablayoutBodyMovie.setupWithViewPager(viewpagerBodyMovie);
        return view;
    }

    private void init() {
        fragments = new ArrayList<>();
        pagerAdapter = new MovieFragmentPagerAdapter(getFragmentManager(), fragments);
    }

    private void addFragment() {
        RecommendFragment recommendFragment = new RecommendFragment();
        Bundle recommendBundle = new Bundle();
        recommendBundle.putString("title", "推荐");
        recommendFragment.setArguments(recommendBundle);

        HotFragment hotFragment = new HotFragment();
        Bundle hotBundle = new Bundle();
        hotBundle.putString("title", "热映影片");
        hotFragment.setArguments(hotBundle);

        NotShowFragment notShowFragment = new NotShowFragment();
        Bundle notShowBundle = new Bundle();
        notShowBundle.putString("title", "即将上映");
        notShowFragment.setArguments(notShowBundle);

        fragments.add(recommendFragment);
        fragments.add(hotFragment);
        fragments.add(notShowFragment);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);
//        getActivity().setActionBar();
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
//        super.onCreateOptionsMenu(menu, inflater);
        inflater.inflate(R.menu.movie_position, menu);
        Log.i("tag", "完成");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }
}
